package org.geometerplus.zlibrary.text.view.style;

import org.geometerplus.zlibrary.text.model.ZLTextMetrics;
import org.geometerplus.zlibrary.text.view.ZLTextHyperlink;
import org.geometerplus.zlibrary.text.view.ZLTextStyle;

class ZLTextPartiallyDecoratedStyle extends ZLTextDecoratedStyle {
	private final ZLTextStyleDecoration myDecoration;

	ZLTextPartiallyDecoratedStyle(ZLTextStyle base, ZLTextStyleDecoration decoration, ZLTextHyperlink hyperlink) {
		super(base, hyperlink);
		myDecoration = decoration;
	}

	@Override
	protected String getFontFamilyInternal() {
		String decoratedValue = myDecoration.FontFamilyOption.getValue();
		return (decoratedValue.length() != 0) ? decoratedValue : Base.getFontFamily();
	}

	@Override
	protected int getFontSizeInternal(ZLTextMetrics metrics) {
		return Base.getFontSize(metrics) + myDecoration.FontSizeDeltaOption.getValue();
	}

	@Override
	protected boolean isBoldInternal() {
		switch (myDecoration.BoldOption.getValue()) {
			case B3_TRUE:
				return true;
			case B3_FALSE:
				return false;
			default:
				return Base.isBold();
		}
	}

	@Override
	protected boolean isItalicInternal() {
		switch (myDecoration.ItalicOption.getValue()) {
			case B3_TRUE:
				return true;
			case B3_FALSE:
				return false;
			default:
				return Base.isItalic();
		}
	}

	@Override
	protected boolean isUnderlineInternal() {
		switch (myDecoration.UnderlineOption.getValue()) {
			case B3_TRUE:
				return true;
			case B3_FALSE:
				return false;
			default:
				return Base.isUnderline();
		}
	}

	@Override
	protected boolean isStrikeThroughInternal() {
		switch (myDecoration.StrikeThroughOption.getValue()) {
			case B3_TRUE:
				return true;
			case B3_FALSE:
				return false;
			default:
				return Base.isStrikeThrough();
		}
	}

	@Override
	public int getLeftIndent() {
		return Base.getLeftIndent();
	}

	@Override
	public int getRightIndent() {
		return Base.getRightIndent();
	}

	@Override
	public int getFirstLineIndentDelta() {
		return Base.getFirstLineIndentDelta();
	}

	@Override
	public int getLineSpacePercent() {
		return Base.getLineSpacePercent();
	}

	@Override
	protected int getVerticalShiftInternal() {
		return Base.getVerticalShift() + myDecoration.VerticalShiftOption.getValue();
	}

	@Override
	public int getSpaceBefore() {
		return Base.getSpaceBefore();
	}

	@Override
	public int getSpaceAfter() {
		return Base.getSpaceAfter();
	}

	@Override
	public byte getAlignment() {
		return Base.getAlignment();
	}

	@Override
	public boolean allowHyphenations() {
		switch (myDecoration.AllowHyphenationsOption.getValue()) {
			case B3_FALSE:
				return false;
			case B3_TRUE:
				return true;
			default:
				return Base.allowHyphenations();
		}
	}

	@Override
    public int getFirstLineSpacePercent() {
	    // TODO Auto-generated method stub
	    return Base.getFirstLineSpacePercent();
    }
}
